import { Component, OnInit } from '@angular/core';
import { LoginService } from './login.service';
import * as _ from 'lodash';
import { DataService } from '../../../services/data.service';

@Component({
	selector: 'app-login',
	templateUrl: './login.component.html',
	styleUrls: ['./login.component.scss'],
	providers: [LoginService]
})
export class LoginComponent implements OnInit {

	constructor(
		public loginService: LoginService,
		public dataService: DataService
	) { }

	public userInfo: any = {
		username: '',
		password: ''
	}
	ngOnInit() {

	}
	login() {
		let token = this.userInfo.username;
		sessionStorage.setItem('token', token);
		this.dataService.hasLoginInfo = true;
		this.loginService.getMenuTree(token).subscribe((data) => {
			if (data) {
				if (data.children.length == 0) {
					sessionStorage.setItem('blankPage', '1');
					window.location.href = '/#/pages/info';
				} else {
					sessionStorage.setItem('blankPage', '0');
					sessionStorage.setItem('currentTitle', "首页");
					sessionStorage.removeItem('menu');
					let menu = JSON.stringify(data.children)
					sessionStorage.setItem('menu', menu);
					window.location.href = '/#/pages/dashboard/home';
				}
			}
		})
		sessionStorage.setItem('token', this.userInfo.username);
	}


}
